{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "00c5f09d",
   "metadata": {},
   "source": [
    "### Python基础"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5644be20",
   "metadata": {},
   "source": [
    "Python使用缩进来组织代码块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9808bb2b",
   "metadata": {},
   "source": [
    "### 数据类型"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5bbd788a",
   "metadata": {},
   "source": [
    "#### 整数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c14a9b58",
   "metadata": {},
   "source": [
    "Python可以处理任意大小的整数，当让包括负整数。\n",
    "对于很大的数，很难清楚0的个数食，允许在数字中间以_分隔，因此10_000_000和10000000是完全一样的。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e48fa3",
   "metadata": {},
   "source": [
    "#### 浮点数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65888212",
   "metadata": {},
   "source": [
    "浮点数就是小数，对于很大或很小的浮点数，用科学计数法表示：1.23e9.另外整数运算时精确的，浮点数运算可能会有四舍五入。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5769462",
   "metadata": {},
   "source": [
    "#### 字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d323682",
   "metadata": {},
   "source": [
    "字符串以单引号'或双引号\"\"括起来的任意文本。如果字符串内部包含’又包含\"\"，可以用转义字符\\来标识"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f997862e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm \"OK\"!\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m \\\"OK\\\"!')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9ed64de",
   "metadata": {},
   "source": [
    "转义字符\\可以转义很多字符，如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "469a86ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I'm ok.\n",
      "I'm learning\n",
      "Python.\n",
      "\\\n",
      "\\\n"
     ]
    }
   ],
   "source": [
    "print('I\\'m ok.')\n",
    "print('I\\'m learning\\nPython.')\n",
    "print('\\\\\\n\\\\')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76d0c2cf",
   "metadata": {},
   "source": [
    "如果字符串里面很多字符都需要转义，那么可以用r''表示''内部的字符串默认不转义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "147e9df7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\\\\\\t\\\\\n"
     ]
    }
   ],
   "source": [
    "print(r'\\\\\\t\\\\')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b670196",
   "metadata": {},
   "source": [
    "如果字符串内部有很多换行，python允许用'''...'''的格式表示多行内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e7da665b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "line1\n",
      "line2\n",
      "line3\n"
     ]
    }
   ],
   "source": [
    "print('''line1\n",
    "... line2\n",
    "... line3''')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d648814",
   "metadata": {},
   "source": [
    "#### 布尔值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d4e33fb",
   "metadata": {},
   "source": [
    "布尔值只有True和False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d0b3fe8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 > 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81aefb1c",
   "metadata": {},
   "source": [
    "布尔值可以用and, or, not运算，即逻辑运算中的与或非。\n",
    "布尔值经常用在条件判断中。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b4d30b4",
   "metadata": {},
   "source": [
    "#### 空值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bfab81e",
   "metadata": {},
   "source": [
    "None"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "deba4985",
   "metadata": {},
   "source": [
    "#### 变量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6221fb8d",
   "metadata": {},
   "source": [
    "变量本身类型不固定的语言惩治为动态语言，与之对应的是静态语言。静态语言在定义变量时必须指定变量类型，如果赋值不匹配则会报错。Java是静态语言。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ebaa0ef",
   "metadata": {},
   "source": [
    "理解变量在计算机内存中的表示。当我们写a = 'ABC'时，Python解释器干了两件事：1.在内存中创建了一个‘ABC’的字符串；2.在内存中创建了一个名为a的变量，并把它指向‘ABC’。也可以把a的赋值给变量b，实际上是b指向a所指向的数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5f77fde2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ABC\n"
     ]
    }
   ],
   "source": [
    "a = 'ABC'\n",
    "b = a\n",
    "a = 'XYZ'\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f64b03b",
   "metadata": {},
   "source": [
    "#### 常量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f56dd081",
   "metadata": {},
   "source": [
    "在Python中，通常用全部大写的变量名表示常量："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e3fed155",
   "metadata": {},
   "outputs": [],
   "source": [
    "PI = 3.1415926"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87a9da65",
   "metadata": {},
   "source": [
    "但实际上，PI仍然是一个变量，python中没有任何机制保证PI不会被改变"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c45afa9",
   "metadata": {},
   "source": [
    "python中的除法，/计算结果是浮点数，//地板除即保留整数部分，忽略小数部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "159150e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6.0\n",
      "3\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "print(18/3)\n",
    "print(10//3)\n",
    "print(10%3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "231209fe",
   "metadata": {},
   "source": [
    "### 小结"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f74bde54",
   "metadata": {},
   "source": [
    "Python的整数没有大小限制，浮点数也没有大小限制，但是超出一定范围就直接表示为inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "135ca81f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
